/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: app2022 - Ex5
 * <p>Powered by webrx On 2022-02-08 11:14:36
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex5 {
    public static void main(String[] args) {
        new Thread(() -> {
            while (true) {
                try {
                    //TimeUnit.SECONDS.sleep(5);
                    //TimeUnit.DAYS.sleep(30);
                    var c = Calendar.getInstance();
                    //System.out.println(c.get(Calendar.MONTH) + 1);
                    c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
                    c.set(Calendar.DAY_OF_MONTH, 0);
                    c.set(Calendar.HOUR_OF_DAY, 2);
                    c.set(Calendar.MINUTE, 0);
                    c.set(Calendar.SECOND, 0);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    //System.out.println(sdf.format(c.getTime()));
                    if (c.getTimeInMillis() == System.currentTimeMillis()) {
                        //每月的月末，要执行的代码
                        System.out.println(sdf.format(c.getTime()));
                        System.out.printf("%1$tF %1$tT%n", System.currentTimeMillis());
                        //--------------每月的月末，要执行的代码
                        TimeUnit.SECONDS.sleep(2);
                    }
                    //System.out.printf("%1$tF %1$tT%n", System.currentTimeMillis());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
